#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int vaildate(char* s) {
	int lcount = 0;

	while (*s != 0) {
		if (*s == '{') {
			lcount++;
		}
		else if (*s == '}') {
			lcount--;
			if (lcount < 0) {
				return 0;
			}
		}
		s++;
	}
	if (lcount == 0) {
		return 1;
	} else {
		return 0;
	}
}

int main(){
	char str[64];
	int n;
	scanf("%d",&n);
	while (n-- > 0) {
		scanf("%60s", str);
		puts(vaildate(str) == 0 ? "no" : "yes");
	}
}